package com.yyt.elasticsearch.dao.impl;

import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

public class ProductPriceDaoImpl {

    @Autowired
    private RestHighLevelClient client;

    // 返回 费用明细
    public String getRecommendProduct(int category_id, int product_id, Date fees_date) {
//        prod_transport_name???应该是产品运输方式

        // prod_keywords 的模糊匹配
        SearchRequest searchRequest = new SearchRequest("productprice");  // 设置搜索的 index
//        searchRequest.types("doc");  // 设置搜索的 type

        MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder("prod_transport_name", transport_code);
        matchQueryBuilder.fuzziness(Fuzziness.AUTO);
        matchQueryBuilder.prefixLength(3);
        matchQueryBuilder.maxExpansions(10);

        TransportClient client = new PreBuiltTransportClient(settings)
                //获取es主机中节点的ip地址及端口号(以下是单个节点案例)
                .addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.1.94"), 9300));
        QueryBuilder builder = QueryBuilders.matchQuery("interests", "changge");
        SearchResponse response = client.prepareSearch("lib3").setQuery(builder).get();
        SearchHits hits = response.getHits();

        QueryBuilder multiMatch = QueryBuilders.multiMatchQuery("prod_id", "category_id","fees_date");
        SearchResponse response = client.prepareSearch("lib").setQuery(multiMatch).get();
    }

    // 返回 其他服务
    public String getRecommendProduct(int category_id, int product_id, Date fees_date) {
//        prod_transport_name???应该是产品运输方式

        // prod_keywords 的模糊匹配
        SearchRequest searchRequest = new SearchRequest("productprice");  // 设置搜索的 index
//        searchRequest.types("doc");  // 设置搜索的 type

        MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder("prod_transport_name", transport_code);
        matchQueryBuilder.fuzziness(Fuzziness.AUTO);
        matchQueryBuilder.prefixLength(3);
        matchQueryBuilder.maxExpansions(10);

        TransportClient client = new PreBuiltTransportClient(settings)
                //获取es主机中节点的ip地址及端口号(以下是单个节点案例)
                .addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.1.94"), 9300));
        QueryBuilder builder = QueryBuilders.matchQuery("interests", "changge");
        SearchResponse response = client.prepareSearch("lib3").setQuery(builder).get();
        SearchHits hits = response.getHits();

        QueryBuilder multiMatch = QueryBuilders.multiMatchQuery("prod_id", "category_id","fees_date");
        SearchResponse response = client.prepareSearch("lib").setQuery(multiMatch).get();
    }

    // 返回 计费单位列表
    public String getRecommendProduct(int category_id, int product_id, Date fees_date) {
//        prod_transport_name???应该是产品运输方式

        // prod_keywords 的模糊匹配
        SearchRequest searchRequest = new SearchRequest("productprice");  // 设置搜索的 index
//        searchRequest.types("doc");  // 设置搜索的 type

        MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder("prod_transport_name", transport_code);
        matchQueryBuilder.fuzziness(Fuzziness.AUTO);
        matchQueryBuilder.prefixLength(3);
        matchQueryBuilder.maxExpansions(10);

        TransportClient client = new PreBuiltTransportClient(settings)
                //获取es主机中节点的ip地址及端口号(以下是单个节点案例)
                .addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.1.94"), 9300));
        QueryBuilder builder = QueryBuilders.matchQuery("interests", "changge");
        SearchResponse response = client.prepareSearch("lib3").setQuery(builder).get();
        SearchHits hits = response.getHits();

        QueryBuilder multiMatch = QueryBuilders.multiMatchQuery("prod_id", "category_id","fees_date");
        SearchResponse response = client.prepareSearch("lib").setQuery(multiMatch).get();
    }
}
